Use master
Go
Create Database DiaryOnline
Go
Use DiaryOnline
Go
Create Table Diary
(
	DiaryID int identity(1,1) Primary Key,
	Username varchar(50) not null unique,
	[Password] varchar(200) not null,
	Email varchar(50) not null,
	FirstName nvarchar(50),
	LastName nvarchar(50)
)
Go
Create Table DiaryEntry
(
	DiaryEntryID bigint identity(1,1) Primary Key,
	DiaryID int References Diary(DiaryID) not null,
	EntryDate datetime not null,
	EntryTitle nvarchar(50) not null,
	EntryText nvarchar(2000) not null,
	DateChanged datetime not null
)
Go
Create Table Contact
(
	ContactID bigint identity(1,1) Primary Key,
	DiaryID int References Diary(DiaryID) not null,
	FirstName nvarchar(50),
	LastName nvarchar(50),
	Telephone varchar(50),
	MobilePhone varchar(50),
	Email nvarchar(250),
	AddressLine1 nvarchar(150),
	City nvarchar(100),
	[State] nvarchar(100),
	PostalCode varchar(50)
)
Go
Create Table DiaryEvent
(
	EventID bigint identity(1,1) Primary Key,
	DiaryID int References Diary(DiaryID) not null,
	EventName nvarchar(50) not null,
	EventDescription nvarchar(250),
	EventDate datetime not null,
	EventDuration int not null
)